home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / C / XMSSTUFF.ZIP / XMS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-07  |  2.8 KB  |  128 lines

  1. #include <dos.h>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <memory.h>
  5. #include <malloc.h>
  6. #include "xmsstuff.h"
  7.  
  8. main()
  9. {
  10.     char _far *temp;
  11.     unsigned int handle;
  12.     unsigned int memavail;
  13.     unsigned int a;
  14.     unsigned char _far *dataptr;
  15.     int off;
  16.  
  17.     if( XMS_detect() )
  18.         printf( "XMS drive found.\n");
  19.     else
  20.         printf( "XMS driver not found.\n");
  21.     XMS_ini();
  22.     printf( "XMS Version Number = %u.\n", XMSVersion );
  23.     printf( "Largest XMS memory block = %uKb\n", XMS_largestavail());
  24.     memavail = XMS_memavail();
  25.     printf( "Total free XMS memory = %uKb\n", memavail);
  26.     if( memavail < 64 )
  27.     {
  28.         printf( "not enough memory to continue test.\n" );
  29.     }
  30.     printf( "allocating 64Kb\n");
  31.     handle = XMS_allocate_block( 64 );
  32.     if( handle == 255 )
  33.     {
  34.         printf( "XMS allocation failed. error = %d\n", error);
  35.         exit( 1 );
  36.     }
  37.     printf( "XMS allocation sucsessful: handle = %u\n", handle );
  38.     printf( "Total free XMS handles = %u\n",XMS_handles_free( handle ) );
  39.     memavail = XMS_memavail();
  40.     printf( "Total free XMS memory = %uKb\n", memavail);
  41.     printf( "Begining to transfer data to XMS.\n");
  42.  
  43.     if( (dataptr = (char far *)_fmalloc( (size_t)64000)) == NULL )
  44.     {
  45.         printf( "Insuffent conventional memory available.\n");
  46.         exit( 1 );
  47.     }
  48.  
  49.     for( a = 0; a < 64000; a ++ )
  50.         dataptr[a] = a % 4;
  51.  
  52.     if( !XMSE_con_to_xms( handle, dataptr, (unsigned int)64000 ) )
  53.     {
  54.         printf( "XMS Move failed.  Your in trouble now!!\n");
  55.         exit( 1 );
  56.     }
  57.     else
  58.         printf( "XMS Move sucsessful.\n");
  59.  
  60.     printf( "Clearing memory.\n");
  61.     for( a = 0; a < 64000; a ++ )
  62.         dataptr[a] = 0;
  63.  
  64.     printf( "Attempting to lock XMS memory.\n");
  65.     if( (temp = XMS_lock_block( handle )) == NULL )
  66.     {
  67.         printf( "Could not lock XMS handle.\n" );
  68.         exit ( 0 );
  69.     }
  70.     printf( "XMS handle locked. Ptr = %pH \n", temp );
  71.     printf( "Enabling A20 line.\n" );
  72.  
  73.     if( !XMS_enable_A20() )
  74.     {
  75.         printf( "Could not enable A20.\n");
  76.         exit( 0 );
  77.     }
  78.     printf( "Enabled A20.\n");
  79.     printf( "Disabling A20 line.\n" );
  80.     if( !XMS_disable_A20() )
  81.     {
  82.         printf( "Could not disable A20.\n");
  83.         exit( 0 );
  84.     }
  85.     printf( "Disabled A20.\n");
  86.  
  87.     if( !XMS_unlock_block( handle ) )
  88.     {
  89.         printf( "Could not unlock XMS handle.\n" );
  90.         exit ( 0 );
  91.     }
  92.     printf( "XMS handle unlocked.\n" );
  93.  
  94.  
  95.     if( !XMSE_xms_to_con( handle, dataptr, (unsigned int)64000 ) )
  96.     {
  97.         printf( "XMS Move failed.  Your in trouble now!!\n");
  98.         exit( 1 );
  99.     }
  100.     else
  101.         printf( "XMS Move sucsessful.\n");
  102.  
  103.     off = 0;
  104.     for( a = 0; a < 64000; a ++ )
  105.         if( dataptr[a] != a % 4 )
  106.         {
  107.             off ++;
  108.             printf( "Block %d doesn't match.\n", a);
  109.         }
  110.  
  111.     printf( "%u nonmatching entries found.\n", off );
  112.  
  113.     if( XMS_free_block( handle ) )
  114.         printf( "XMS free_block sucsessful.\n");
  115.     else
  116.     {
  117.         printf( "XMS free_block not sucsessful. error = %d\n", error );
  118.         exit( 1 );
  119.     }
  120.  
  121.     _ffree( dataptr );
  122.     exit ( 0 );
  123. }
  124.  
  125.  
  126.  
  127.  
  128.